const mysql = require (`mysql`);
const dbConfig = require(`../config/dbconfig.js`)
const connection = mysql.createConnection(dbConfig);

connection.connect(function (err) {
    if (err) {
        throw err;
    }
    console.log(`connect mysql 成功`)
});

function dbQuery(sql) {
    return new Promise((resolve, reject) => {
        connection.query(sql, (err, result) => {
            if (err) {
                reject(err)
            } else {
                resolve(result)
            }
        })
    })
}
module.exports = dbQuery;